import { Controller, Get, Post, Body, Query } from '@nestjs/common'
import { Prisma } from '@prisma/client'
import { FoodService } from './food.service'

@Controller('food')
export class FoodController {
  constructor(private readonly foodService: FoodService) {}

  @Post()
  async createFood(@Body() data: Prisma.FoodCreateInput) {
    const food = await this.foodService.createFood(data)
    return {
      statusCode: 200,
      message: 'OK',
      data: {
        food
      }
    }
  }

  @Get()
  async getFoods() {
    const foods = await this.foodService.getFoods()
    return {
      statusCode: 200,
      message: 'OK',
      data: {
        foods
      }
    }
  }

  @Get('search')
  async searchFoods(@Query('word') word: string) {
    const foods = await this.foodService.searchFoods(word)
    return {
      statusCode: 200,
      message: 'OK',
      data: {
        foods
      }
    }
  }
}
